package cn.shop.dys.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;

import java.util.List;

import cn.shop.dys.R;
import cn.shop.dys.bean.ListFilterBean;
import cn.shop.dys.widget.FreeFilterView;
import cn.shop.lib_common.CommonViewHolder;

/**
 * Created by sugar0811 on 2016/4/22.
 */
public class LVRightAdapter extends BaseAdapter {

    private Context context;
    private List<ListFilterBean> items;
    private FreeFilterView item_show_first;
    private FreeFilterView item_show_second;
    private FreeFilterView item_show_thirdly;

    public LVRightAdapter(Context context, List<ListFilterBean> items) {
        this.items = items;
        this.context = context;
    }

    @Override
    public int getCount() {
        return 1;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CommonViewHolder holder = CommonViewHolder.getCommonViewHolder(convertView, context, R.layout.view_select_right);
        item_show_first = holder.getView(R.id.item_show_first);
        item_show_second =  holder.getView(R.id.item_show_second);
        item_show_thirdly =  holder.getView(R.id.item_show_thirdly);
        Button bt_first = holder.getView(R.id.bt_first);
        Button bt_second =  holder.getView(R.id.bt_second);
        Button bt_thirdly =  holder.getView(R.id.bt_thirdly);
        bt_first.setText(items.get(0).getKey());
        bt_second.setText(items.get(1).getKey());
        bt_thirdly.setText(items.get(2).getKey());
        bt_first.setTag(R.id.bt_first);
        bt_second.setTag(R.id.bt_second);
        bt_thirdly.setTag(R.id.bt_thirdly);
        setListener(bt_first);
        setListener(bt_second);
        setListener(bt_thirdly);
        return holder.convertView;
    }

    private void setListener(Button bt_first) {

        bt_first.setOnClickListener(listener);
    }

    View.OnClickListener listener = new View.OnClickListener() {


        @Override
        public void onClick(View v) {

            if(v.getId() == R.id.bt_first) {
                disPatch(v,item_show_first);
            }if(v.getId() == R.id.bt_second) {
                disPatch(v,item_show_second);
            }if(v.getId() == R.id.bt_thirdly) {
                disPatch(v,item_show_thirdly);
            }
        }
    };

    private void disPatch(View v,FreeFilterView b) {
        if (callBack != null) {
            int id = (int) v.getTag();
            callBack.onClickFilter(id,b);

        }
    }

    private CallBack callBack;

    public interface CallBack {

        void onClickFilter(int id, FreeFilterView freeFilterView);

    }

    public void setCallBack(CallBack callBack) {


        this.callBack = callBack;
    }
}
